package ru.avn.devtool4j.spi.writers.impl;

import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.List;

public class WritterHelper {

	
	public static String endLine(String line) {
		line = line.trim();
		
		if (!line.endsWith(";")) {
			line = line + ";";
		}
		
		return line;
	}
	
	
	public static String modifiers(int[] modifiers) {
		Arrays.sort(modifiers);
		
		
		StringBuilder builder = new StringBuilder();
		
		for (int mod :modifiers) {
			builder.append(Modifier.toString(mod))
				.append(" ");
		}
		
		if (builder.length() > 0)
		builder.setLength(builder.length() - 1);
	
		
		return builder.toString();
	}
	
	
	public static String join(String[] strings, String joinWith) {
		return join(Arrays.asList(strings), joinWith);
	}
	
	public static String join(List<String> strings, String joinWith) {
		StringBuilder builder = new StringBuilder();
		if (strings != null && strings.size() > 0) {
			builder.append(strings).append(joinWith);
		}
		if (builder.length() > joinWith.length()) {
			builder.setLength(builder.length() - joinWith.length());
		}
		return builder.toString();
	}
	
}
